﻿using ModSim32.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace ModSim32
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            string temp = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ModSim32\\";
            if (!Directory.Exists(temp))
                Directory.CreateDirectory(temp);

            string f = temp + "Modbusl.dll";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.Modbusl_dll);
            f = temp + "modsim32.cfg";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.modsim32_cfg);
            f = temp + "ModSim32.cnt";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ModSim32_cnt);
            f = temp + "ModSim32.exe";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ModSim32_exe);
            f = temp + "MODSIM32.GID";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.MODSIM32_GID);
            f = temp + "MODSIM32.HLP";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.MODSIM32_HLP);
            f = temp + "ModSim32.ini";
            if (!File.Exists(f))
                File.WriteAllText(f, Resources.ModSim32_ini);
            f = temp + "ModSim32.tlb";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ModSim32_tlb);
            f = temp + "ModSimEx.frm";
            if (!File.Exists(f))
                File.WriteAllText(f, Resources.ModSimEx_frm);
            f = temp + "ModSimEx.vbp";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ModSimEx_vbp);
            f = temp + "ModSimEx.vbw";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ModSimEx_vbw);
            f = temp + "Modsim.lpu";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.Modsim_lpu);
            f = temp + "ms32comm.cfg";
            if (!File.Exists(f))
                File.WriteAllBytes(f, Resources.ms32comm_cfg);

            f = temp + "ModSim32.exe";
            Process.Start(f);
        }
    }
}
